package com.hanxiaozhang.order.feign.fallback;

import com.hanxiaozhang.order.entity.User;
import com.hanxiaozhang.order.feign.OldOrderFeignHystrixClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author hanxinghua
 * @create 2020/7/3
 * @since 1.0.0
 */
@Slf4j
@Component
public class OldOrderFeignHystrixFallbackFactory implements FallbackFactory<OldOrderFeignHystrixClient> {


    @Override
    public OldOrderFeignHystrixClient create(Throwable throwable) {

        return new OldOrderFeignHystrixClient() {
            @Override
            public User findById(Long id) {
                // 日志最好放在各个fallback方法中，而不要直接放在create方法中。否则在引用启动时，就会打印该日志。
                User user = new User();
                user.setId(-1L);
                user.setUsername("默认用户");
                return user;
            }

        };
    }
}
